<template>
	<view class="">
		<view class="data_input">
			<input type="number" placeholder="请输入手机号" maxlength="11" v-model="phone" />
			<input type="text" placeholder="请输入昵称" maxlength="11" v-model="nickname" />
			<view class="data_input_name" @click="get_search_list">搜索</view>
			<view class="data_input_clear" @click="clear_search_list">清除</view>
		</view>
		<scroll-view :scroll-y="true" class="scroll-box" @touchend="scroll_lower_client" lower-threshold="20">
			<view v-if="data_list.length > 0" class="padding-horizontal-main padding-top-main">
				<view v-for="(item, index) in data_list" :key="index"
					class="padding-main border-radius-main oh bg-white pr spacing-mb line dis_info"
					v-if="(item.phone || null)!=null">
					<!-- <navigator :url="item.goods_url" hover-class="none"> -->
					<image class="goods-image fl radius" @error="user_avatar_error"
						:src="((item.avatar|| null)!=null)?item.avatar:default_avatar" mode="aspectFill"></image>
					<view class="goods-base">
						<view class="goods_info">
							<view class="goods-title multi-text">{{item.nickname}}</view>
							<view class="goods_info_time">{{item.createTime}}</view>
						</view>
						<view class="size">{{item.shopUser.userName ? '业务经理：' + item.shopUser.userName:''}}</view>
						<view class="goods_icon">
							<view class="phone_info oh margin-top-sm" @tap="telFun" :data-tel="item.phone">
								<view class="sales_icon">
									<image
										src="https://t1.chowtaiking.com.cn/img/ruoyi/2025/03/10/49c89337dd51491799f6691d9cfeda65.png"
										mode="widthFix"></image>
								</view>
								<text class="sales-price">{{item.phone}}</text>
							</view>
							<view class="modified_yjf">积分:{{item.integral}}</view>
							<view class="modified_integral" :data-value="item.numberId" :data-nickname="item.nickname" @tap="open">
								<view class="modified_jf">
									<view class="">修改</view>
									<view class="">积分</view>
								</view>
							</view>
							<view class="check" :data-value="item.numberId" :data-index="index" @click="changeCheck" v-if="item.vipCertification == 0">审核</view>
							<view class="check" v-else>已审核</view>
							
						</view>
					</view>

					<!-- </navigator> -->
					<!-- <button class="br-yellow cr-yellow bg-white fr round pa operate-submit" type="default" size="mini" @tap="cancel_event" :data-value="item.numberId" :data-index="index" hover-class="none" v-if="item.vipCertification==0 && power==0">通过</button> -->
				</view>
			</view>
		</scroll-view>
		<!-- 修改积分 -->
		<uni-popup ref="popup" type="center" :animation="false">
			<view class="popup_integral">
				<view class="popup_integral_title">可以对 <text>{{nickname}}</text> 用户积分进行修改</view>
				<input type="digit" v-model="integral" placeholder="请输入积分" />
				<view class="popup_integral_modify" @tap="modified_integral_envent">修改</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		props:['data_list'],
		data() {
			return {
				default_avatar: app.globalData.data.default_user_head_src,
				integral: '',
				numberId: '',
				nickname: '',
				phone: '',
				nickname:'',
				data_page: 1,
				data_list_client:[],
				power: 1,
				data_total_client: 0,
				data_page_total_client: 0,
				data_page_client: 1,
				data_list_loding_status_client: 1,
				data_bottom_line_status_client: false,
			}
		},
		methods: {
			scroll_lower_client() {
				this.$emit('scroll_lower_client')
			},
			telFun(event) {
				this.$emit('telFun', event)
			},
			popup_close_event(event) {
				this.$emit('popup_close_event', event)
			},
			open(e) {
				this.numberId = e.currentTarget.dataset.value || '';
				this.nickname = e.currentTarget.dataset.nickname || '';
				this.$refs.popup.open('center')
			},
			// 修改用户积分
			modified_integral_envent() {
				var post_data = {
					numberId: this.numberId,
					integral: this.integral
				}
				var url = app.globalData.data.request_admin_url + 'member/members/modified';
				uni.request({
					url: url,
					method: "POST",
					data: post_data,
					header: {
						'Authorization': 'Bearer ' + app.globalData.data.admin_token
					},
					success: (res) => {
						if (res.data.code == 200) {
							var data = res.data.data;
							uni.showToast({
								title: "操作成功"
							})
							setTimeout(function() {
								uni.switchTab({
									url: "/pages/user/user"
								})
							}, 2000);
						}
					}
				})
			},
			// 审核
			changeCheck(e) {
				uni.showModal({
					title: "温馨提示",
					content: "通过后用户即可查看批发价，确定继续吗?",
					confirmText: "确定",
					cancelText: "不了",
					complete: (res) => {
						if (res.confirm) {
							// 参数
							var id = e.currentTarget.dataset.value;
							var index = e.currentTarget.dataset.index;
							uni.showLoading({
								title: "审核中...",
								mask: true
							})
							uni.request({
								url: app.globalData.get_request_url("manager/update", "update"),
								method: 'POST',
								data: {
									id: id
								},
								header: {
									'Authorization': 'Bearer ' + app.globalData.data.admin_token
								},
								dataType: 'json',
								success: res => {
									uni.hideLoading();
									if (res.data.code == 200) {
										var temp_data_list = this.data_list_client;
										temp_data_list[index].vipCertification = 1;
										this.data_list_client = temp_data_list;
										if (temp_data_list.length == 0) {
											this.data_list_loding_status_client = 0;
											this.data_bottom_line_status_client = false;
										}
										app.globalData.showToast(res.data.msg, 'success');
									}
								},
								fail: () => {
									uni.hideLoading();
									app.globalData.showToast('服务器请求出错');
								}
							});
						}
					}
				})
			},
			// 清除搜索
			clear_search_list(){
				this.phone = '';
				this.nickname = '';
				this.data_list_client = [];
				this.$emit('reset_data');
			},
			// 客户管理获取数据
			get_search_list(is_mandatory) {
				// 分页是否还有数据
				if ((is_mandatory || 0) == 0) {
					if (this.data_bottom_line_status_client == true) {
						// uni.stopPullDownRefresh();
						return false;
					}
				}
				// 加载loding
				uni.showLoading({
					title: '加载中...'
				});
				this.data_list_loding_status_client = 1;
				let url = app.globalData.get_request_url("manager/index");
				// 获取数据
				uni.request({
					url: url,
					method: 'POST',
					data: {
						page: this.data_page_client,
						phone:this.phone,
						nickname:this.nickname
					},
					header: {
						'Authorization': 'Bearer ' + app.globalData.data.admin_token
					},
					dataType: 'json',
					success: res => {
						uni.hideLoading();
						uni.stopPullDownRefresh();
						if (res.data.code == 200) {
							var data = res.data.data;
							this.power = data.power;
							this.data_list_client = data.data.rows;
							this.$emit('update:data_list', this.data_list_client);
							console.log(this.data_list_client,"this.data_list_client");
						}
					},
					fail: () => {
						uni.hideLoading();
						uni.stopPullDownRefresh();
						uni.showToast({
							title: '服务器请求出错'
						})
					}
				});
			},

		}
	}
</script>

<style lang="less">
	.data_input {
		display: flex;
		align-items: center;
		justify-content: space-around;
		background-color: white;
		padding: 20rpx;

		input {
			width: 200rpx;
			height: 40rpx;
			text-align: center;
			border: 1px solid gray;
			border-radius: 20rpx;
			font-size: 11px;
		}

		.data_input_name {
			font-size: 11px;
			background-color: deepskyblue;
			color: white;
			padding: 10rpx;
			border-radius: 10rpx;
		}
		.data_input_clear{
			background-color: red;
			font-size: 11px;
			color: white;
			padding: 10rpx;
			border-radius: 10rpx;
		}
	}

	/**
	 * 滚动标签高度
	 */
	.scroll-box {
		height: 100vh;
	}

	/**
	 * 存在基础导航
	 */
	.scroll-box-ece-nav {
		height: calc(100vh - 80rpx);
	}

	.padding-horizontal-main {
		padding-left: 20rpx;
		padding-right: 20rpx;
		padding-bottom: 150rpx;
	}

	.padding-top-main {
		padding-top: 20rpx;
	}

	// .padding-main {
	//    padding-bottom: 120rpx;
	// }
	.border-radius-main {
		border-radius: 20rpx;
	}

	.oh {
		overflow: hidden;
	}

	.bg-white {
		background-color: #fff !important;
	}

	.pr {
		position: relative;
	}

	.spacing-mb {
		margin-bottom: 20rpx;
	}

	.fl {
		float: left;
	}

	.radius {
		border-radius: 10rpx !important;
	}

	.multi-text {
		max-width: 100%;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		// min-height: 76rpx;
		// line-height: 38rpx;
		font-size: 28rpx;
		white-space: initial;
	}

	.goods-title {
		padding-top: 10rpx;
	}

	.margin-top-sm {
		margin-top: 30rpx;
	}

	.margin-top-sm button {
		background-color: white;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.margin-top-sm button::after {
		border: none;
	}

	.sales-price {
		color: #1296db;
		font-weight: bold;
		font-size: 28rpx;
	}

	.goods_icon {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.phone_info {
		display: flex;
		align-items: center;
	}

	.sales_icon image {
		width: 50rpx;
		height: 50rpx !important;
	}

	.wx_icon {
		margin-left: 60rpx;
	}

	.wx_icon image {
		width: 50rpx;
		height: 50rpx !important;
	}

	.size {
		font-size: 13px;
		color: gray;
		padding-top: 5rpx;
	}

	.modified_yjf {
		font-size: 12px;
		color: red;
		margin-bottom: -30rpx;
	}

	.modified_integral {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 11px;
		padding-right: 10rpx;
		margin-bottom: -30rpx;
	}
	.modified_jf{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.check {
		font-size: 11px;
		padding-right: 10rpx;
		margin-bottom: -30rpx;
	}

	.goods-base {
		width: 80%;
		min-height: 160rpx;
		margin-left: 20rpx;
	}
	.goods_info{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 10rpx;
	}
	.goods_info_time{
		font-size: 12px;
		color: gray;
	}

	.goods-image {
		width: 160rpx;
		height: 160rpx;
	}

	.operate-submit {
		right: 20rpx;
		bottom: 20rpx;
	}

	.line {
		border: 1rpx solid #e1e1e1;
	}

	.dis_info {
		display: flex;
		align-items: center;
	}

	// 修改积分
	.popup_integral {
		background-color: white;
		width: 570rpx;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.popup_integral_title {
			text-align: center;
			padding-top: 30rpx;
			font-size: 12px;

			text {
				color: red;
				font-size: 14px;
			}
		}

		input {
			margin: 30rpx;
			background-color: #f2f2f2;
			font-size: 11px;
			height: 60rpx;
			text-align: center;
			line-height: 60rpx;
		}

		.popup_integral_modify {
			width: 100rpx;
			height: 40rpx;
			border-radius: 20rpx;
			line-height: 40rpx;
			background-color: red;
			color: white;
			font-size: 12px;
			text-align: center;
			margin-bottom: 30rpx;
		}
	}
</style>